﻿
namespace LiteBlog.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using LiteBlog.Common;
    using LiteBlog.Components;
    using LiteBlog.Common.Entities;
    using System.Web.Script.Serialization;
    using LiteBlog.Common.Components;
    using LiteBlog.Common.Enums;
    using LiteBlog.Components.Contracts;
    using LiteBlog.Components.Enums;
    using LiteBlog.Controllers.Filters;
    using LiteBlog.Controllers.Contracts;


    public class AuthorController : CompController<Author, string>, IAuthorController
    {
        private IAuthorComp _authorComponent;

        public AuthorController(IAuthorComp authorComponent, ISettingsComp settingsComp, ICacheComp cacheComp)
            : base(authorComponent, settingsComp, cacheComp)
        {
            _authorComponent = authorComponent;
        }

        public override ActionResult Manage()
        {
            return base.Manage();
        }

        public override ActionResult Create(Author model)
        {
            return base.Create(model);
        }

        public override ActionResult Update(string olid, Author model)
        {
            return base.Update(olid, model);
        }

        public override ActionResult Delete(string id)
        {
            return base.Delete(id);
        }

        [Authorize]
        [AjaxExceptionFilter]
        public ActionResult Unlock(string id)
        {
            var result = _authorComponent.Unlock(id);
            var resultModel = GetResultModel(result, id);
            return Json(resultModel, JsonRequestBehavior.AllowGet);
        }

        [Authorize]
        [AjaxExceptionFilter]
        public ActionResult MakePrimary(string id)
        {
            var result = _authorComponent.MakePrimary(id);
            var resultModel = GetResultModel(result, id);
            return Json(resultModel, JsonRequestBehavior.AllowGet);
        }


        [Authorize]
        [AjaxExceptionFilter]
        public ActionResult Disable(string id, bool enable = false)
        {
            var result = _authorComponent.Disable(id, enable);
            var resultModel = GetResultModel(result, id);
            return Json(resultModel, JsonRequestBehavior.AllowGet);
        }

        protected override string[] GetMessageParams(Author model)
        {
            return new string[] { model.ID, model.Email };
        }

        public override void ResolveComponents()
        {
            
        }
    }
}